package com.example.redisdemo;

import redis.clients.jedis.Jedis;

import java.util.*;

public class test {
    public static void main(String[] args) {
redisHash();
Jedis jedis = new Jedis("localhost",6379);
redisHashMap(jedis);
    }


    public static void  redisHash(){
        Jedis jedis = new Jedis("127.0.0.1",6379);

        Set<String> keySets = new HashSet<>();
        keySets = jedis.keys("*");

        List <Map<String,String>> hashList = new ArrayList<>();

        for (String s:keySets){
            if(jedis.type(s).equals("hash")){
               hashList.add(jedis.hgetAll(s));
            }

        }


    }

    public static void redisInit(){
        Jedis jedis = new Jedis("127.0.0.1",6379);
        List<String> nameList = new ArrayList<>();

        //创建10个学生，以10个hash存放在redis
        for (int i=0;i<10;i++){
            nameList.add("modige"+i);
            Map<String,String> map = new HashMap<>();
            map.put("sno",""+i);
            map.put("sname","modige"+i);
            map.put("sage",""+(i+21));
            jedis.hmset(""+i,map);
        }
        System.out.println(jedis.hgetAll(""+0));

    }

    public static void redisHashMap(Jedis jedis){
        Map<String,String> map = new HashMap();
        map.put("key","value");
        map.put("key1","value");
        map.put("key2","value");
        jedis.hmset("hashtest",map);
        System.out.println(jedis.hmget("hashtest","key","key1"));

    }

}
